package Day36.equals;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Comparator;
import java.util.Date;
import java.util.TreeSet;

public class Test3 {
    public static void main(String[] args) throws ParseException {
       // TreeSet<User> users = new TreeSet<>();//使用user对象中的默认排序规则进行排序
       // TreeSet<User> users = new TreeSet<>(new User.sortByUserIdDESC());
        TreeSet<User> users = new TreeSet<>(new Comparator<User>() {
            //使用匿名内部类实现比较器接口
            @Override
            public int compare(User user1, User user2) {
                return user1.getRegDate().compareTo(user2.getRegDate());
            }
        });
        User user1 = new User(1,"admin1",100,new Date());
        User user2 = new User(2,"admin2",80,new SimpleDateFormat("yyyy-MM-dd").parse("2020-12-10"));
        User user3 = new User(3,"admin3",290,new SimpleDateFormat("yyyy-MM-dd").parse("2018-10-12"));
        User user4 = new User(4,"admin4",300,new SimpleDateFormat("yyyy-MM-dd").parse("2019-06-10"));
        users.add(user1);
        users.add(user2);
        users.add(user3);
        users.add(user4);
        for (User user :users
             ) {
            System.out.println(user);
        }
    }
}
